#include "include.h"
#include "func.h"

//音效模式简单实例 用户根据实际需要添加
#define MODE_MAGIC                0xA1
#define MODE_ECHO                 0xA2
#define MODE_ECHO_MAGIC           0xA3
#define MODE_PLATE_REVERB         0xA4
#define MODE_MUTE_DAC             0xA5

AT(.text.func.wireless_mic)
void func_adapter_message(u16 msg)
{
    switch (msg) {
    case KU_PLAY:
    case KU_PLAY_USER_DEF:
    case KU_PLAY_PWR_USER_DEF:
        //usb_device_hid_send(UDE_HID_PLAYPAUSE, 1);
        break;

    case KU_VOL_DOWN:
    case KL_VOL_DOWN:
    case KH_VOL_DOWN:
        //usb_device_hid_send(UDE_HID_VOLDOWN, 1);
        break;

    case KU_VOL_UP:
    case KL_VOL_UP:
    case KH_VOL_UP:
        //usb_device_hid_send(UDE_HID_VOLUP, 1);
        break;

    case KL_PLAY_PWR_USER_DEF:
    case KL_PLAY_USER_DEF:
        break;
#if ADAPTER_USB_MIC_RX_EN
    case EVT_PC_INSERT:
        printf("EVT_PC_INSERT\n");
        usb_device_enter(UDE_ENUM_TYPE);
        break;

    case EVT_PC_REMOVE:
        printf("EVT_PC_REMOVE\n");
        usb_device_exit();
        break;
#endif

#if  WARNING_TONE_EN
    case EVT_WIRELESS_CONNECTED_WARNING:
        mp3_res_play(RES_BUF_CONNECTED_MP3, RES_LEN_CONNECTED_MP3);//提示音播放，自行更换所需提示音文件
        break;
    case EVT_WIRELESS_DISCONNECTED_WARNING:
        mp3_res_play(RES_BUF_DISCONNECT_MP3, RES_LEN_DISCONNECT_MP3);//提示音播放，自行更换所需提示音文件
        break;
#endif // WARNING_TONE_EN

    case MODE_MAGIC:
        printf("MODE_MAGIC\n");
        ///切换模式过程中统一关闭所有算法处理
        dac_out_audio_mute_set(1);
        #if ADAPTER_MAGIC_EN
        magic_audio_mute_set(1);
        #endif
        #if ADAPTER_ECHO_EN
        echo_audio_mute_set(1);
        #endif
        #if ADAPTER_PLATE_REVERB_EN
        plate_reverb_audio_mute_set(1);
        #endif
        #if ADAPTER_MAGIC_EN
        ///设置magic参数 当前模式单独运行魔音算法
        magic_audio_param_set(18000);
        #endif // ADAPTER_MAGIC_EN

        #if ADAPTER_MAGIC_EN
        magic_audio_mute_set(0);
        #endif
        #if ADAPTER_ECHO_EN
        echo_audio_mute_set(1);
        #endif
        #if ADAPTER_PLATE_REVERB_EN
        plate_reverb_audio_mute_set(1);
        #endif

        dac_out_audio_mute_set(0);
        break;
    case MODE_ECHO:
        printf("MODE_ECHO\n");
        ///切换模式过程中统一关闭所有算法处理
        dac_out_audio_mute_set(1);
        #if ADAPTER_MAGIC_EN
        magic_audio_mute_set(1);
        #endif
        #if ADAPTER_ECHO_EN
        echo_audio_mute_set(1);
        #endif
        #if ADAPTER_PLATE_REVERB_EN
        plate_reverb_audio_mute_set(1);
        #endif

        #if ADAPTER_ECHO_EN
        ///设置echo参数 当前模式单独运行echo
        echo_audio_param_set(55,250,3000,0,32768,29491);
        #endif // ADAPTER_ECHO_EN

        #if ADAPTER_MAGIC_EN
        magic_audio_mute_set(1);
        #endif
        #if ADAPTER_ECHO_EN
        echo_audio_mute_set(0);
        #endif
        #if ADAPTER_PLATE_REVERB_EN
        plate_reverb_audio_mute_set(1);
        #endif

        dac_out_audio_mute_set(0);
        break;
    case MODE_ECHO_MAGIC:
        printf("MODE_ECHO_MAGIC\n");
        ///切换模式过程中统一关闭所有算法处理
        dac_out_audio_mute_set(1);
        #if ADAPTER_MAGIC_EN
        magic_audio_mute_set(1);
        #endif
        #if ADAPTER_ECHO_EN
        echo_audio_mute_set(1);
        #endif
        #if ADAPTER_PLATE_REVERB_EN
        plate_reverb_audio_mute_set(1);
        #endif

        #if ADAPTER_ECHO_EN
        ///设置模式参数
        echo_audio_param_set(55,250,3000,0,32768,29491);
        #endif // ADAPTER_ECHO_EN

        #if ADAPTER_MAGIC_EN
        magic_audio_param_set(-20000);
        #endif // ADAPTER_MAGIC_EN

        ///开启对应算法处理
        #if ADAPTER_MAGIC_EN
        magic_audio_mute_set(0);
        #endif
        #if ADAPTER_ECHO_EN
        echo_audio_mute_set(0);
        #endif
        #if ADAPTER_PLATE_REVERB_EN
        plate_reverb_audio_mute_set(1);
        #endif

        dac_out_audio_mute_set(0);
        break;
    case MODE_PLATE_REVERB:
        printf("MODE_PLATE_REVERB\n");
        dac_out_audio_mute_set(1);

        #if ADAPTER_MAGIC_EN
        magic_audio_mute_set(1);
        #endif
        #if ADAPTER_ECHO_EN
        echo_audio_mute_set(1);
        #endif
        #if ADAPTER_PLATE_REVERB_EN
        plate_reverb_audio_mute_set(1);
        #endif

        ///REVERB 参数设置不支持动态修改

        #if ADAPTER_MAGIC_EN
        magic_audio_mute_set(1);
        #endif
        #if ADAPTER_ECHO_EN
        echo_audio_mute_set(1);
        #endif
        #if ADAPTER_PLATE_REVERB_EN
        plate_reverb_audio_mute_set(0);
        #endif
        delay_5ms(10);
        dac_out_audio_mute_set(0);
        break;
    case MSG_SYS_1S:
        break;
    default:
        func_message(msg);
        break;
    }
}
